package com.clkj.xiuzheng.dao.shangcheng;

import com.clkj.xiuzheng.pojo.shangcheng.VipLevel;
import com.clkj.xiuzheng.pojo.shangcheng.VipLevelNum;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;
import java.util.Set;

@Repository
public interface ScVipMapper extends Mapper<VipLevel>, MySqlMapper<VipLevel> {
    @Select("select * from t_xz_vipLevelNum where company_id = #{companyId}")
    Set<VipLevelNum> getLevelByCompanyId(@Param("companyId") Integer companyId);

     @Select("select v.*, n. level_id as levelId , n.vip_level_number as level ,n.next_score as nextScore,n.level_name as levelName from t_xz_vipLevel v left join t_xz_vipLevelNum n on v.level_id = n.vip_level_number where n.vip_level_number = #{vipLevel} and v.company_id =#{companyId}")
    List<VipLevel> selectByLevelIdAndCompanyId(@Param("vipLevel") Integer vipLevel, @Param("companyId") Integer companyId);

    @Insert("insert into t_xz_vipLevelNum(company_id,vip_level_number,level_name,next_score) values(#{companyId},#{vipLevelNumber},#{levelName},#{nextScore})")
    @Options(useGeneratedKeys = true, keyProperty = "levelId")
    void addVipLevel(VipLevelNum vipLevelNum);

    @Delete("delete from t_xz_vipLevel where vip_id = #{vipId}")
    void deleteVipLevel(Integer vipId);


    @Update("UPDATE t_xz_vipLevel" +
            " SET level_money = #{levelMoney}, level_score = #{levelScore}," +
            " level_diamond = #{levelDiamond}, give_money = #{giveMoney}, company_id = #{companyId}, level_id = #{levelId}," +
            " level_status = #{levelStatus}, dueTime = #{dueTime}, level_product = #{levelProduct}," +
            " remarks = #{remarks}" +
            " WHERE vip_id = #{vipId}")
    void updateEditVipLevel(VipLevel vipLevel);

}
